package com.example.testanimation.graphics.old;

import java.io.FileDescriptor;
import java.io.PrintWriter;

import android.content.Context;
import android.graphics.Canvas;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;

import com.lenovo.nova.util.BaseActivity;
import com.lenovo.nova.util.DebugUtil;
import com.lenovo.nova.util.DebugUtil.OnDumpExecuteListener;

public class GraphicsActivity extends BaseActivity {

	int intervel = 10;
	
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
//		View view = new MyUserSuffaceView(this);
		View view = new MyView(this);
		setContentView(view);
		
		DebugUtil.getInstance(this).setOnDumpExecuteListener(new OnDumpExecuteListener() {


            @Override
            public boolean onDumpExecute(DebugUtil util, String prefix, FileDescriptor fd, PrintWriter writer, String[] args, String cmdValue) {
				int cmd = util.nextCmdValueAsInt();
				switch(cmd){
				case 0:
					int value = util.nextCmdValueAsInt();
					intervel = 30 - value*3;
					animation.setLevel(value);
					break;
				}
				return false;
			}
		});
	}

	MyAnimation animation = null;
	class MyView extends View {
		public MyView(Context context) {
			super(context);
			animation = new MyAnimation(context);
			animation.setAnimationIndex(2);
		}
		
		public Handler hander = new Handler(){
			public void handleMessage(android.os.Message msg) {
				switch(msg.what){
				case 0:
					invalidate();
					break;
				}
			};
		};
		
		public void refresh(){
			hander.sendEmptyMessageDelayed(0, intervel);
		}
		
		@Override
		protected void onDraw(Canvas canvas) {
			super.onDraw(canvas);
			animation.draw(canvas);
			animation.refresh(19,200);
			refresh();
		}
		
		
	}

}
